package com.feiyu.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * aop  测试运行的时间
 */
@Slf4j
@Component
@Aspect   //aop类
//@Order(2)         //设置通知的顺序
public class TimeAspect2 {

    @Around("execution(* com.feiyu.service.*.*(..))")
    //切入点表达式
    public Object TotalTime(ProceedingJoinPoint pjp) throws Throwable {

        long start = System.currentTimeMillis();
        //执行原始方法
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info(pjp.getSignature() + "执行耗时： {}毫秒" , (end - start));
        return result;

    }


    @Before("execution(* com.feiyu.service.*.*(..))")
    public void Before(){
        log.info("TimeAspect2----before");
    }


    @After("execution(* com.feiyu.service.*.*(..))")
    public void After(){
        log.info("TimeAspect2----After");
    }


}
